/**
 *
 */
package swa2012.telco.client.gui.elements;

//package elements;

import java.util.Map;
import java.util.LinkedHashMap;
import java.util.Collection;

/**
 * @author lukas schober
 * @date 10.06.2012
 */
public class guiGenerator {

	private Map<Integer,guiView> guiViews;
	private Map<Integer,String> guiViewsString;

	public guiGenerator(){
		this.guiViews = new LinkedHashMap<Integer,guiView>();
		this.guiViewsString = new LinkedHashMap<Integer,String>();
		for(int i = 0; i<5; i++){
			guiView tmpview = new guiView();
			this.guiViews.put(i, tmpview);
		}

		setguiViews();

		setguiViewsString();
	}

	public void setguiViews(){

		for(Integer i = 0; i<this.getguiViews().size(); i++ ){

			switch(i){
				case 0:{
					String vName = "HELP";
					Map<String,String> vValue = new LinkedHashMap<String,String>(){{
					put("#Head", "### Hilfe #########\n");
					put("#1", "Hier eine Liste aller Befehle:\n" +
									 " - getmyM | holt meine Nachrichten vom Provider" +
									 " - list | Listet alles verbundenen Clients auf\n" +
									 " - sendto XY message | schickt eine Nachricht an XY\n" +
									 " - disconnect | beendet die Verbindung\n" +
									 " - help | ruft die Hilfe auf\n");
					put("#Footer", "### Hilfe #########\n");}};
					this.getguiViews().get(i).setvName(vName);
					this.getguiViews().get(i).setvAttributes(vValue);
					break;
				}
				case 1:{
					String vName = "MESSAGESEND";
					Map<String,String> vValue = new LinkedHashMap<String,String>();
					vValue.put("#Head", "### Nachricht gesendet #########\n");
					vValue.put("#1", "From: ");vValue.put("#FROM", "");vValue.put("#2", " | ");vValue.put("#TO", "");vValue.put("#3", " | ");vValue.put("#TIME", "");
					vValue.put("#Message", "\n\n");
					vValue.put("#Footer", "### Nachricht gesendet #########\n");
					this.getguiViews().get(i).setvName(vName);
					this.getguiViews().get(i).setvAttributes(vValue);
					break;
				}
				case 2:{
					String vName = "MESSAGERECE";
					Map<String,String> vValue = new LinkedHashMap<String,String>();
					vValue.put("#Head", "### Nachricht empfangen #########\n");
					vValue.put("#1", "From: ");vValue.put("#FROM", "");vValue.put("#2", " | ");vValue.put("#TO", "");vValue.put("#3", " | ");vValue.put("#TIME", "");
					vValue.put("#Message", "\n\n");
					vValue.put("#Footer", "### Nachricht empfangen #########\n");
					this.getguiViews().get(i).setvName(vName);
					this.getguiViews().get(i).setvAttributes(vValue);
					break;
				}
				case 3:{
					String vName = "CONNECT";
					Map<String,String> vValue = new LinkedHashMap<String,String>();
					vValue.put("#Head", "### Verbindungs-Aufbau #########\n");
					vValue.put("#1", "From: ");vValue.put("#FROM", "");vValue.put("#2", " | ");vValue.put("#TO", "");
					vValue.put("#Message", "\n\n");
					vValue.put("#Footer", "### Verbindunds-Aufbau #########\n");
					this.getguiViews().get(i).setvName(vName);
					this.getguiViews().get(i).setvAttributes(vValue);
					break;
				}
				case 4:{
					String vName = "LISTUSERS";
					Map<String,String> vValue = new LinkedHashMap<String,String>();
					vValue.put("#Head", "### UserListe #########\n");
					vValue.put("#1", "Liste aller verfügbaren User:\n ");
					vValue.put("#Message", "\n\n");
					vValue.put("#Footer", "### UserListe #########\n");
					this.getguiViews().get(i).setvName(vName);
					this.getguiViews().get(i).setvAttributes(vValue);
					break;
				}
				case 5:{
					String vName = "DISCONNECT";
					Map<String,String> vValue = new LinkedHashMap<String,String>();
					vValue.put("#Head", "### Verbindungs-Abbau #########\n");
					vValue.put("#1", "From: ");vValue.put("#FROM", "");vValue.put("#2", " | ");
					vValue.put("#Message", "\n\n");
					vValue.put("#Footer", "### Verbindunds-Abbau #########\n");
					this.getguiViews().get(i).setvName(vName);
					this.getguiViews().get(i).setvAttributes(vValue);
					break;
				}
				default:{
					String vName = "NOVIEW";
					Map<String,String> vValue = new LinkedHashMap<String,String>();
					vValue.put("#Head", "### FalscherView #########\n");
					vValue.put("#1", "Hier wurde auf einen nicht vorhanden View verwiesen.\n");
					vValue.put("#Footer", "### FalscherView #########\n");
					this.getguiViews().get(i).setvName(vName);
					this.getguiViews().get(i).setvAttributes(vValue);
					break;
				}
			}

		}

	}

	public void setguiViewsString(){
		int i = 0;
		Map<Integer, guiView> currentState = this.getguiViews();

		Collection<guiView> valueCollection = currentState.values();

		for(guiView item: valueCollection){
			this.guiViewsString.put(i, item.getvValue());
			i++;
		}
	}

	public void setguiViewsString(Integer id){
		guiView currentState = this.getguiViews(id);
		this.guiViewsString.put(id, currentState.getvValue());
	}


	public Map<Integer,guiView> getguiViews(){
		return this.guiViews;
	}

	public guiView getguiViews(Integer i){
		return this.guiViews.get(i);
	}

	public guiView getguiViews(String vName){
		for(int i = 0; i<this.guiViews.size();i++){
			if(this.guiViews.get(i).getvName().equals(vName)){
				return this.guiViews.get(i);
			}
		}
		return null;
	}

	public int getguiViewsID(String vName){
		for(int i = 0; i<this.guiViews.size();i++){
			if(this.guiViews.get(i).getvName().equals(vName)){
				return i;
			}
		}
		return -1;
	}

	public void setguiViews(String vName, LinkedHashMap<String,String> change ){
		this.guiViews.get(this.getguiViewsID(vName)).setvAttributes(change);
		setguiViewsString(this.getguiViewsID(vName));
	}

	public void setguiViews(Integer id, LinkedHashMap<String, String> change){
		this.guiViews.get(id).setvAttributes(change);
		setguiViewsString(id);
	}

	public String getALLguiViewsString(){
		String result = "";
		for(int i = 0; i<this.guiViewsString.size(); i++){
			result = result + guiViewsString.get(i) + "\n";
		}
		return result;
	}

	public String getguiViewsString(Integer i){
		return this.guiViewsString.get(i);
	}

	public String getguiViewsString(String vName){
		int i = 0;
		Map<Integer, guiView> currentState = this.getguiViews();

		Collection<guiView> valueCollection = currentState.values();

		for(guiView item: valueCollection){
			if(item.getvName().equals(vName)){
				return item.getvValue();
			}
			i++;
		}
		return "View nicht gefunden!\n";
	}
}
